package com.sgb.kjwl.view.ui.activity.lookingforAJob;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityLookingforAJobBinding;
import com.sgb.kjwl.di.lookingforAJob.LookingforAJobModule;
import com.sgb.kjwl.di.lookingforAJob.DaggerLookingforAJobComponent;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.view.ui.fragment.machine.MachineListFragment3;
import com.sgb.kjwl.viewmodel.lookingforAJob.LookingforAJobModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;
import com.swgk.core.util.MLog;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
@Deprecated
public class LookingforAJobActivity extends AppActivity {

    @Inject
    LookingforAJobModel viewModel;

    private ActivityLookingforAJobBinding binding;
    private FragPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments;
    private String[] titles;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerLookingforAJobComponent.builder().appComponent(appComponent)
                .lookingforAJobModule(new LookingforAJobModule(this))
                .build()
                .inject(this);
    }


    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, LookingforAJobActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_lookingfor_a_job);
        binding.ivBack.setVisibility(View.VISIBLE);
        binding.ivBack.setOnClickListener(view -> finish());
        binding.rightView.setOnClickListener(view -> showFilterPop());
    }

    @Override
    protected void init() {
        viewModel.getFilterTypeModel();
    }

    public void showTypeView(List<DictEntity3> data) {
        if (data == null || data.size() == 0) {
            return;
        }
        mFragments = new ArrayList<>();
        int size = data.size();
        titles = new String[size];
        for (int i = 0; i < size; i++) {
            mFragments.add(MachineListFragment3.newInstance());
            titles[i] = data.get(i).getName();
        }
        pagerAdapter = new FragPagerAdapter(getSupportFragmentManager(), mFragments);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(titles.length - 1);
        binding.tablayout.setViewPager(binding.viewpager, titles);
    }

    public void changeType(int position) {
        binding.viewpager.setCurrentItem(position);
    }

    private void showFilterPop() {


    }
}